const uniObj_goods = uniCloud.importObject("sm-goods-obj",{
	//customUI: true // 取消自动展示的交互提示界面
});
const state={
	goodsList:[],
	total:0,
	goodsInfo:{}
};
const mutations={
	GETGOODSLIST(state,result){
		state.goodsList = result.data;
		state.total = result.count;
	},
	GETGOODSINFO(state,result){
		state.goodsInfo = result.data;
	}
};
const actions={
	async getGoodsList({commit},categoryId){
		try{
			const result = await uniObj_goods.getGoodsList(categoryId);
			if(result.code==0){
				commit('GETGOODSLIST',result);
			}
		}catch(e){
			uni.switchTab({
				url:`/pages/my/my`
			})
		}
		
	},
	async getGoodsInfo({commit},_id){
		try{
			const result = await uniObj_goods.getGoodsInfo(_id);
			if(result.code==0){
				commit('GETGOODSINFO',result);
			}
		}catch(e){
			uni.switchTab({
				url:`/pages/my/my`
			})
		}
		
	},
};
const getters={
	pageList(state){
		let pages = Math.ceil(state.total/18);
		console.log(pages,'pages')
		let pageArray = [];
		// pages.forEach((item,index)=>{
		// 	pageArray.push(item);
		// });
		for(let i=1;i<=pages;i++){
			pageArray.push(i);
	
		}
		return pageArray || [];
	}
};
export default {
	state,
	mutations,
	actions,
	getters
}